package com.test_phone.slice;

import com.test_phone.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Text;

public class MainAbilitySlice extends AbilitySlice {
    Button button1,button2, button3,button4,button5,button6,button7,button8,button9;
    StringBuffer stringBuffer;
    Button[] buttons;
    Text text1;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        text1 = (Text) this.findComponentById(ResourceTable.Id_text);
        button1 = (Button) this.findComponentById(ResourceTable.Id_button1);
        button2= (Button) this.findComponentById(ResourceTable.Id_button2);
        button3 = (Button) this.findComponentById(ResourceTable.Id_button3);
        button4 = (Button) this.findComponentById(ResourceTable.Id_button4);
        button5 = (Button) this.findComponentById(ResourceTable.Id_button5);
        button6 = (Button) this.findComponentById(ResourceTable.Id_button6);
        button7 = (Button) this.findComponentById(ResourceTable.Id_button7);
        button8 = (Button) this.findComponentById(ResourceTable.Id_button8);
        button9 = (Button) this.findComponentById(ResourceTable.Id_button9);
        buttons = new Button[]{button1,button2, button3,button4,button5,button6,button7,button8,button9};
        stringBuffer  = new StringBuffer();
      for (int i=0;i<=9;i++){
          int finalI = i;
          buttons[i].setClickedListener(new Component.ClickedListener() {
              @Override
              public void onClick(Component component) {
                  String text = buttons[finalI].getText();
                  String s = stringBuffer.append(text).toString();
                  text1.setText(s);
              }
          });


      }
        };






    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
